﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Collections;
using System.IO;
using System.Drawing;
using System.Text;

public partial class dayin : System.Web.UI.Page
{
  
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["name"] == null)
        {
            Response.Redirect("~/error.aspx?");
        }

        if (!IsPostBack)
        {
            this.bind();
        }

    }
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) 
    {
        if (e.Row.RowIndex > -1) 
        {
            e.Row.Cells[0].Text = Convert.ToString(e.Row.RowIndex + 1);
                //e.Row.Cells; 
           TableCell tc1 = new TableCell();
        TextBox beizhu = new TextBox();
        //bianhao.ID = "bianhao" + Table1.Rows.Count;
       // bianhao.Text = Table1.Rows.Count.ToString();
       // tc3.Controls.Add(bianhao);
        tc1.Controls.Add(beizhu);
           // e.Row.Cells.Add(beizhu);
        } 
    }
    protected void bind()
    {
        SqlConnection myConn = GetConnection();
        myConn.Open();
        //string sqlStr = "select RID as 编号 , RGID as 货品编号,GTYPEName as 类别,GCHName as 名称,GXinhao as 型号,GBrand as 品牌,  RWID as 仓库编号,RQuantity as 数量,RHandler as 出货人,RDate as 日期, RifAOG as 出货确认,RComfirmer as 确认人,RComfirmedDate as 确认日期,  bianhao as 项目编号,PName as 项目名 from Projects,RecordsOUT, Goods where RecordsOUT.RGID=Goods.GID and RecordsOUT.RPID=Projects.PID and RecordsOUT.RDID='" + Session["ODID"].ToString() + "' order by RID desc";
        string sqlStr = "select GCHName as 名称,GXinhao as 型号, RQuantity as 数量,GBrand as 品牌 from Projects,RecordsOUT, Goods where RecordsOUT.RGID=Goods.GID and RecordsOUT.RPID=Projects.PID and RecordsOUT.RDID='" + Session["ODID"].ToString() + "' order by RID desc";
        string sqlCont = "select ContAdd as 地址,ContTel as 电话,ContName as 联系人,DName as 货单,PName as 项目名称,DPurp as 发货目的,DEng as 主管工程师 from Contacts,Projects,Dan where Contacts.Did='" + Session["ODID"].ToString() + "' and Dan.DPid=Projects.PID and Contacts.Did=Dan.id";

        SqlCommand cmd1 = new SqlCommand(sqlCont, myConn);
        cmd1.ExecuteNonQuery();
        SqlDataReader readdizhi = cmd1.ExecuteReader();
        readdizhi.Read();
        
        string dizhi = readdizhi["地址"].ToString();
        string dianhua = readdizhi["电话"].ToString();
        string lianxiren = readdizhi["联系人"].ToString();
        string mingcheng = readdizhi["项目名称"].ToString();
        string gongchegnshi = readdizhi["主管工程师"].ToString();
        //int mudi = int.Parse(readdizhi["发货目的"].ToString());
        string mudi=readdizhi["发货目的"].ToString();
        if (mudi != null)
        {
            int mudi_int = int.Parse(mudi);
            checkbox(mudi_int, CheckBoxList1);
        }
        //checkbox(mudi, CheckBoxList1);
        lianxiren1.Text = lianxiren;
        dizhi1.Text = dizhi;
        dianhua1.Text = dianhua;
        mingcheng1.Text = mingcheng;
        gongchengshi1.Text = gongchegnshi;
        readdizhi.Dispose();
        SqlDataAdapter myDa = new SqlDataAdapter(sqlStr, myConn);
        DataSet myDs = new DataSet();
        myDa.Fill(myDs);
        GridView1.DataSource = myDs;
        int[] 序号 = new int[6] { 1, 2, 3, 4, 5, 6 };
        SqlDataAdapter myda2 = new SqlDataAdapter(sqlCont, myConn);
        DataSet myds2 = new DataSet();


        myda2.Fill(myds2);
        
        //GridView1.DataKeyNames = new string[] { "编号" };
        //GridView1.DataKeyNames = new string[] { "序号" };
        //GridView1.datas
        GridView1.DataBind();
        myDa.Dispose();
        myDs.Dispose();
        myConn.Close();
    }
    public void checkbox(int i,CheckBoxList boxlist)
    {
        boxlist.Items[i].Selected = true;
       
    }
    public SqlConnection GetConnection()
    {
        string myStr = ConfigurationManager.AppSettings["ConnectionString"].ToString();
        SqlConnection myConn = new SqlConnection(myStr);
        return myConn;
    }

    protected void setborder(TextBox box)
    {
        box.BorderStyle = BorderStyle.None;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        setborder(songhuoren);
        setborder(lianxiren1);
        setborder(dianhua1);
        setborder(gongchengshi1);
        setborder(mingcheng1);
        setborder(dizhi1);
       // setborder(TextBox2);
        setborder(tbBeginTime);
       // setborder(TextBox3);
        setborder(TextBox13);
        Button1.Visible = false;

    }
}